package com.szkiti.myautils.dialog;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;

import com.szkiti.myautils.R;
/**
 * 通用圆形加载ProgressBar
 * @author WangLinkai
 *
 */
public class ProgressDialogUtils {

	 private static Dialog dialog = null;
	 
	 /**
	  * 
	  * @param context
	  * @param msg  传入的提示信息，不传入则默认为 “玩命加载中~~~”
	  */
	 @SuppressLint("CutPasteId")
	 public static void show(Context context,String msg) {
		 
		if(dialog != null && dialog.isShowing()) {
			return;
		}
		
		LayoutInflater inflater = LayoutInflater.from(context);
		View loadingView = inflater.inflate(R.layout.loading, null);
		
		//加载ImageView
        ImageView spaceshipImage = (ImageView) loadingView.findViewById(R.id.progressImg);  
	    TextView loadingMsg = (TextView)loadingView.findViewById(R.id.loadingMsg);// 提示文字  
	    
	    if(msg != null && !"".equals(msg)) {
            loadingMsg.setText(msg);// 设置加载信息  
        }
	    
        // 加载动画  
        Animation hyperspaceJumpAnimation = AnimationUtils.loadAnimation(context, R.anim.loading);  
        // 使用ImageView显示动画  
        spaceshipImage.startAnimation(hyperspaceJumpAnimation);  
       
		Dialog loadingDialog = new Dialog(context,R.style.loading_dialog);
		loadingDialog.setContentView(loadingView,new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
		loadingDialog.setCancelable(true);
		loadingDialog.show();
		dialog = loadingDialog;
	}
	
	public static void disMiss() {
		if(dialog != null) {
			dialog.dismiss();
			dialog = null;
		}
	}
}
